package org.lanqiao.lg.dao.impl;

import java.sql.SQLException;
import java.util.List;

import org.apache.commons.dbutils.handlers.BeanListHandler;
import org.apache.commons.dbutils.handlers.ScalarHandler;
import org.lanqiao.bean.Label;
import org.lanqiao.lg.dao.LabelDao;
import org.lanqiao.tools.BaseDao;

public class LabelDaoImpl extends BaseDao implements LabelDao  {
//	根据id查找标签内容 并返回
	@Override
	public String searchContent(Integer id) {
		try {
			return query.query("select content from label where id=?", new ScalarHandler<String>(),id);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}
	
// 根据标签内容查找id 并返回
	@Override
	public Integer searchLabelId(Label info) {
		try {
			 return query.query("SELECT id FROM label WHERE content=?", new ScalarHandler<Integer>(),info.getContent());
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
//添加新的标签
	@Override
	public Integer insertLabel(Label info) {
		try {
			 query.update("INSERT INTO label(content,stateId,date) VALUES(?,1,NOW())",
						info.getContent());
			 return query.query("SELECT id FROM label WHERE content=?", new ScalarHandler<Integer>(),info.getContent());
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

//	@Override 查询所有标签
	public List<Label> selectAll() {
		try {
			return query.query("select * from label", new BeanListHandler<Label>(Label.class));
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
	

	
}
